<template>
  <div class="previewYard">
    <el-row>
      <el-col :span="20">
        <el-form :model="ruleForm"
                 :rules="rules"
                 ref="ruleForm"
                 label-width="120px"
                 class="ruleForm">
          <el-form-item label="堆场名称"
                        prop="yardName">
            <el-input v-model="ruleForm.yardName"
                      class="normal-input"
                      :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="堆场长度(mm)"
                        prop="yardLength">
            <el-input v-model="ruleForm.yardLength"
                      class="normal-input"
                      :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="堆场宽度(mm)"
                        prop="yardWidth">
            <el-input v-model="ruleForm.yardWidth"
                      class="normal-input"
                      :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="堆场示意图">
            <el-upload class="avatar-uploader"
                       action="https://jsonplaceholder.typicode.com/posts/"
                       :show-file-list="false"
                       accept=".jpg,.png,.jpeg"
                       :disabled="true">
              <img v-if="imageUrl"
                   :src="imageUrl"
                   class="avatar">
              <i v-else
                 class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import axios from 'axios'
import qs from 'qs'
export default {
  data () {
    return {
      ruleForm: {
        yardName: '',
        yardLength: '',
        yardWidth: '',
        imgUrl: '',
      },
      imageUrl: '',
      uuid: this.$route.query.uuid,
      rules: {
        yardName: [
          { required: true, message: '请输入堆场名称', trigger: 'blur' },
        ],
        yardLength: [
          { required: true, message: '请输入堆场长度', trigger: 'blur' },
          { type: 'number', message: '宽度必须为数字值' }
        ],
        yardWidth: [
          { required: true, message: '请输入堆场宽度', trigger: 'blur' },
          { type: 'number', message: '宽度必须为数字值' }
        ],
      }
    }
  },
  methods: {
    getData () {
      axios.get('admin/stack/getStackById', {
        params: {
          id: this.$route.query.id,
          uuid: this.uuid
        },
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
      }
      ).then(res => {
        this.ruleForm.yardName = res.data.data.list.name;
        this.ruleForm.yardLength = Number(res.data.data.list.length);
        this.ruleForm.yardWidth = Number(res.data.data.list.width);
        this.ruleForm.imgUrl = res.data.data.list.img;
        if (res.data.data.list.img != '') {
          this.imageUrl = res.data.data.list.path;
        } else {
          this.imageUrl = '/static/img/none.png'
        }
      }, err => {
        console.log(err)
      })
    }

  },
  created () {
    this.getData();
  }
}
</script>
<style lang="scss" scoped>
.previewYard {
  padding: 20px;
  .normal-input {
    width: 300px;
  }
  .avatar-uploader /deep/ .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px !important;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>